/*
Created By VietRise on 4/6/2014
*/

#include "AppDelegate.h"
#include "Scenes\ScreenLoading.h"
#include "Scenes\ScreenStart.h"
#include "Scenes\ScreenGameplay.h"
#include "Scenes\ScreenLevel.h"

USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching() {
	// initialize director
	CCDirector* pDirector = CCDirector::sharedDirector();
	CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

	pDirector->setOpenGLView(pEGLView);

	CCSize screenSize = pEGLView->getFrameSize();
	CCSize designSize = CCSize(800, 480);

	pEGLView->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);

	/*
	if (screenSize.width > 1600)
	{
		CCFileUtils::sharedFileUtils()->addSearchPath("ipadhd");
		pDirector->setContentScaleFactor(2400 / designSize.width);
	}
	else if (screenSize.width > 800)
	{
		CCFileUtils::sharedFileUtils()->addSearchPath("ipad");
		pDirector->setContentScaleFactor(1600 / designSize.width);
	}
	else
	{
		CCFileUtils::sharedFileUtils()->addSearchPath("iphone");
		pDirector->setContentScaleFactor(800 / designSize.width);
	}
	*/	
	pDirector->setDisplayStats(false);

	CCFileUtils::sharedFileUtils()->addSearchPath("iphone");
	pDirector->setContentScaleFactor(800 / designSize.width);
	// set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);

	// create a scene. it's an autorelease object
	CCScene *pScene = ScreenLoading::scene();

	// run
	pDirector->runWithScene(pScene);

	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
	CCDirector::sharedDirector()->stopAnimation();

	// if you use SimpleAudioEngine, it must be pause
	// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
	CCDirector::sharedDirector()->startAnimation();

	// if you use SimpleAudioEngine, it must resume here
	// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
